﻿Imports XL.Common
Imports XL.Common.Utils

Public Class ServiceTK
    Inherits XL.DB.Utils.BaseService



    Public Shared Function GetInstance() As ServiceTK

        Dim result As ServiceTK
        If RExpXAuto.Decls.CURRENT_DB_TYPE = XL.DB.DBDecl.DBType.Remoting Then

            result = CType(Activator.GetObject(GetType(ServiceTK), _
                String.Format("tcp://{0}/ServiceTK.remote", _
                    RExpXAuto.Decls.REMOTE_SERVICE_URL)),  _
                ServiceTK)

            If result.ValidateAuthPassword(CommDecl.CURRENT_LOCAL_REMOTE_AUTH_PASSWORD) = False Then
                Dim ex As New XLException(XLException.ErrorClassify.ReadDataError)
                ex.SetMessage(CommDecl.MSG_ALERT_REMOTE_AUTH_DENIED)
                Throw ex
            End If

        Else

            result = New ServiceTK
        End If

        Return result

    End Function

    Public Sub ServMigrateCacheCallListToDB(ByRef cacheIncomingCallList As RExpXAuto.FTs.FT_H_REXP_INCOMING_CALL)
        Dim handleMinute = CommTK.FInteger( _
                    SysInfo.ReadShareSysInfo( _
                        RExpXService.Decls.SVN_LOCAL_INCOMING_CALL_HANDLE_MINUTE))
        If handleMinute <= 0 Then
            Return
        End If

        Facade.OpBizManage.FillCacheIncomingCallListAbsent(cacheIncomingCallList)

        Dim callCondition As New RExpXAuto.Facade.AfBizManage.ConditionOfH_REXP_INCOMING_CALL(XL.DB.Utils.Condition.LogicOperators.Logic_And)
        callCondition.Add( _
            RExpXAuto.Facade.AfBizManage.H_REXP_INCOMING_CALLColumns.INCOME_TIMEColumn, _
            "<", _
            CommTK.GetSyncServerTime.AddMinutes( _
                -handleMinute))

        For Each callRow In cacheIncomingCallList.FindRowsByCondition(callCondition)
            callCondition.Clear()
            callCondition.Add(RExpXAuto.Facade.AfBizManage.H_REXP_INCOMING_CALLColumns.HISTORY_IDColumn, "=", callRow.HISTORY_ID)
            If RExpXAuto.Facade.AfBizManage.GetH_REXP_INCOMING_CALLCount(callCondition) > 0 Then
                Continue For
            End If

            RExpXAuto.Facade.AfBizManage.CreateH_REXP_INCOMING_CALLInfoByRow(callRow)
        Next

        cacheIncomingCallList.RemoveFT_H_REXP_INCOMING_CALLRows(callCondition)

    End Sub

    Public Sub ServGetAlertData(ByVal valParameter As String, ByVal refResult As String)


    End Sub

    Public Sub ServMakeupNullFields()

        'Dim formCondition As New RExpXAuto.Facade.AfBizDeliver.ConditionOfT_GBL_DELIVER_FORM(XL.DB.Utils.Condition.LogicOperators.Logic_And)

        'formCondition.Add("SIGN_DATE Is Null")
        'RExpXAuto.Facade.AfBizDeliver.ReviseT_GBL_DELIVER_FORMData(formCondition, GoBalanceXAuto.Facade.AfBizDeliver.T_GBL_DELIVER_FORMColumns.SIGN_DATEColumn, CommDecl.NULL_DATE)

        'formCondition.Clear()
        'formCondition.Add("DELIVER_DATE Is Null")

        'RExpXAuto.Facade.AfBizDeliver.ReviseT_GBL_DELIVER_FORMData(formCondition, GoBalanceXAuto.Facade.AfBizDeliver.T_GBL_DELIVER_FORMColumns.DELIVER_DATEColumn, CommDecl.NULL_DATE)

    End Sub



    Public Sub ServInitDefaultCommonItem( _
        ByRef refDEFAULT_CI_VALUE_IDENTITY_CARD_TYPE_RESIDENT As Integer, _
        ByRef refDEFAULT_CI_VALUE_INCOMING_CALL_TRANSACT_WAY_NONE As Integer, _
        ByRef refDEFAULT_CI_VALUE_INCOMING_CALL_TRANSACT_WAY_INFORM_STAFF As Integer, _
        ByRef refDEFAULT_CI_VALUE_INCOMING_CALL_TRANSACT_WAY_IGNORE As Integer _
        )

        Dim itemID As String

        Dim IDENTITY_CARD_TYPE_RESIDENTRow As RExpXAuto.FTs.FT_CIV_IDENTIFY_CARD_TYPERow
        Dim IDENTITY_CARD_TYPE_RESIDENTCondition As New RExpXAuto.Facade.AfCIV.ConditionOfCIV_IDENTIFY_CARD_TYPE(XL.DB.Utils.Condition.LogicOperators.Logic_And)

        IDENTITY_CARD_TYPE_RESIDENTCondition.Clear()
        IDENTITY_CARD_TYPE_RESIDENTCondition.Add(RExpXAuto.Facade.AfCIV.CIV_IDENTIFY_CARD_TYPEColumns.ITEM_MEANINGColumn, " =", RExpXService.Decls.DEFAULT_CI_TEXT_IDENTITY_CARD_TYPE_RESIDENT)
        IDENTITY_CARD_TYPE_RESIDENTRow = RExpXAuto.Facade.AfCIV.GetCIV_IDENTIFY_CARD_TYPERow(IDENTITY_CARD_TYPE_RESIDENTCondition)
        If IsNothing(IDENTITY_CARD_TYPE_RESIDENTRow) = True Then

            itemID = Guid.NewGuid.ToString
            RExpXService.Decls.DEFAULT_CI_VALUE_IDENTITY_CARD_TYPE_RESIDENT = _
                RExpXService.Facade.OpSysConfig.CreateCommonItem( _
                    itemID, _
                    RExpXAuto.Decls.CICNAME_IDENTIFY_CARD_TYPE, _
                    RExpXService.Decls.DEFAULT_CI_TEXT_IDENTITY_CARD_TYPE_RESIDENT, _
                    String.Empty, _
                    True)

        Else
            RExpXService.Decls.DEFAULT_CI_VALUE_IDENTITY_CARD_TYPE_RESIDENT = IDENTITY_CARD_TYPE_RESIDENTRow.ITEM_VALUE
        End If

        refDEFAULT_CI_VALUE_IDENTITY_CARD_TYPE_RESIDENT = RExpXService.Decls.DEFAULT_CI_VALUE_IDENTITY_CARD_TYPE_RESIDENT

        Dim INCOMING_CALL_TRANSACT_WAY_NONERow As RExpXAuto.FTs.FT_CIV_INCOMING_CALL_TRANSACT_WAYRow
        Dim INCOMING_CALL_TRANSACT_WAY_NONECondition As New RExpXAuto.Facade.AfCIV.ConditionOfCIV_INCOMING_CALL_TRANSACT_WAY(XL.DB.Utils.Condition.LogicOperators.Logic_And)

        INCOMING_CALL_TRANSACT_WAY_NONECondition.Clear()
        INCOMING_CALL_TRANSACT_WAY_NONECondition.Add(RExpXAuto.Facade.AfCIV.CIV_INCOMING_CALL_TRANSACT_WAYColumns.ITEM_MEANINGColumn, " =", RExpXService.Decls.DEFAULT_CI_TEXT_INCOMING_CALL_TRANSACT_WAY_NONE)
        INCOMING_CALL_TRANSACT_WAY_NONERow = RExpXAuto.Facade.AfCIV.GetCIV_INCOMING_CALL_TRANSACT_WAYRow(INCOMING_CALL_TRANSACT_WAY_NONECondition)
        If IsNothing(INCOMING_CALL_TRANSACT_WAY_NONERow) = True Then

            itemID = Guid.NewGuid.ToString
            RExpXService.Decls.DEFAULT_CI_VALUE_INCOMING_CALL_TRANSACT_WAY_NONE = _
                RExpXService.Facade.OpSysConfig.CreateCommonItem( _
                    itemID, _
                    RExpXAuto.Decls.CICNAME_INCOMING_CALL_TRANSACT_WAY, _
                    RExpXService.Decls.DEFAULT_CI_TEXT_INCOMING_CALL_TRANSACT_WAY_NONE, _
                    String.Empty, _
                    True)

        Else
            RExpXService.Decls.DEFAULT_CI_VALUE_INCOMING_CALL_TRANSACT_WAY_NONE = INCOMING_CALL_TRANSACT_WAY_NONERow.ITEM_VALUE
        End If

        refDEFAULT_CI_VALUE_INCOMING_CALL_TRANSACT_WAY_NONE = RExpXService.Decls.DEFAULT_CI_VALUE_INCOMING_CALL_TRANSACT_WAY_NONE

        Dim INCOMING_CALL_TRANSACT_WAY_INFORM_STAFFRow As RExpXAuto.FTs.FT_CIV_INCOMING_CALL_TRANSACT_WAYRow
        Dim INCOMING_CALL_TRANSACT_WAY_INFORM_STAFFCondition As New RExpXAuto.Facade.AfCIV.ConditionOfCIV_INCOMING_CALL_TRANSACT_WAY(XL.DB.Utils.Condition.LogicOperators.Logic_And)

        INCOMING_CALL_TRANSACT_WAY_INFORM_STAFFCondition.Clear()
        INCOMING_CALL_TRANSACT_WAY_INFORM_STAFFCondition.Add(RExpXAuto.Facade.AfCIV.CIV_INCOMING_CALL_TRANSACT_WAYColumns.ITEM_MEANINGColumn, " =", RExpXService.Decls.DEFAULT_CI_TEXT_INCOMING_CALL_TRANSACT_WAY_INFORM_STAFF_DELIVER)
        INCOMING_CALL_TRANSACT_WAY_INFORM_STAFFRow = RExpXAuto.Facade.AfCIV.GetCIV_INCOMING_CALL_TRANSACT_WAYRow(INCOMING_CALL_TRANSACT_WAY_INFORM_STAFFCondition)
        If IsNothing(INCOMING_CALL_TRANSACT_WAY_INFORM_STAFFRow) = True Then

            itemID = Guid.NewGuid.ToString
            RExpXService.Decls.DEFAULT_CI_VALUE_INCOMING_CALL_TRANSACT_WAY_INFORM_STAFF_DELIVER = _
                RExpXService.Facade.OpSysConfig.CreateCommonItem( _
                    itemID, _
                    RExpXAuto.Decls.CICNAME_INCOMING_CALL_TRANSACT_WAY, _
                    RExpXService.Decls.DEFAULT_CI_TEXT_INCOMING_CALL_TRANSACT_WAY_INFORM_STAFF_DELIVER, _
                    String.Empty, _
                    True)

        Else
            RExpXService.Decls.DEFAULT_CI_VALUE_INCOMING_CALL_TRANSACT_WAY_INFORM_STAFF_DELIVER = INCOMING_CALL_TRANSACT_WAY_INFORM_STAFFRow.ITEM_VALUE
        End If

        refDEFAULT_CI_VALUE_INCOMING_CALL_TRANSACT_WAY_INFORM_STAFF = RExpXService.Decls.DEFAULT_CI_VALUE_INCOMING_CALL_TRANSACT_WAY_INFORM_STAFF_DELIVER

        Dim INCOMING_CALL_TRANSACT_WAY_IGNORERow As RExpXAuto.FTs.FT_CIV_INCOMING_CALL_TRANSACT_WAYRow
        Dim INCOMING_CALL_TRANSACT_WAY_IGNORECondition As New RExpXAuto.Facade.AfCIV.ConditionOfCIV_INCOMING_CALL_TRANSACT_WAY(XL.DB.Utils.Condition.LogicOperators.Logic_And)

        INCOMING_CALL_TRANSACT_WAY_IGNORECondition.Clear()
        INCOMING_CALL_TRANSACT_WAY_IGNORECondition.Add(RExpXAuto.Facade.AfCIV.CIV_INCOMING_CALL_TRANSACT_WAYColumns.ITEM_MEANINGColumn, " =", RExpXService.Decls.DEFAULT_CI_TEXT_INCOMING_CALL_TRANSACT_WAY_IGNORE)
        INCOMING_CALL_TRANSACT_WAY_IGNORERow = RExpXAuto.Facade.AfCIV.GetCIV_INCOMING_CALL_TRANSACT_WAYRow(INCOMING_CALL_TRANSACT_WAY_IGNORECondition)
        If IsNothing(INCOMING_CALL_TRANSACT_WAY_IGNORERow) = True Then

            itemID = Guid.NewGuid.ToString
            RExpXService.Decls.DEFAULT_CI_VALUE_INCOMING_CALL_TRANSACT_WAY_IGNORE = _
                RExpXService.Facade.OpSysConfig.CreateCommonItem( _
                    itemID, _
                    RExpXAuto.Decls.CICNAME_INCOMING_CALL_TRANSACT_WAY, _
                    RExpXService.Decls.DEFAULT_CI_TEXT_INCOMING_CALL_TRANSACT_WAY_IGNORE, _
                    String.Empty, _
                    True)

        Else
            RExpXService.Decls.DEFAULT_CI_VALUE_INCOMING_CALL_TRANSACT_WAY_IGNORE = INCOMING_CALL_TRANSACT_WAY_IGNORERow.ITEM_VALUE
        End If

        refDEFAULT_CI_VALUE_INCOMING_CALL_TRANSACT_WAY_IGNORE = RExpXService.Decls.DEFAULT_CI_VALUE_INCOMING_CALL_TRANSACT_WAY_IGNORE


    End Sub


    Public Sub RegularSystemValues()


    End Sub

End Class

